/*
 *       This file is part of VFC.
 *
 *        VFC is free software: you can redistribute it and/or modify
 *        it under the terms of the GNU General Public License as published by
 *        the Free Software Foundation, either version 3 of the License, or
 *        (at your option) any later version.
 *
 *        VFC is distributed in the hope that it will be useful,
 *        but WITHOUT ANY WARRANTY; without even the implied warranty of
 *        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *        GNU General Public License for more details.
 *
 *        You should have received a copy of the GNU General Public License
 *        along with VFC.  If not, see <http://www.gnu.org/licenses/>.
 */


using System;
using System.Collections.Generic;
using System.Text;
using System.Globalization;
using System.Windows.Forms;

namespace VFC.Emu
{
    class Misc
    {
        private static int TMP;


        public static char StringHexToChar(string str)
        {
            TMP = 0;
            TMP = int.Parse(str, NumberStyles.AllowHexSpecifier);
            switch (TMP)
            {
                case 0x00 :
                case 0x01 :
                case 0x02 :
                case 0x03 :
                case 0x04 :
                case 0x05 :
                case 0x06 :
                case 0x07 :
                case 0x08 :
                case 0x09 :
                case 0x0a :
                case 0x0b :
                case 0x0c :
                case 0x0d :
                case 0x0e :
                case 0x0f :
                case 0x10 :
                case 0x11 :
                case 0x12 :
                case 0x13 :
                case 0x14 :
                case 0x15 :
                case 0x16 :
                case 0x17 :
                case 0x18 :
                case 0x19 :
                case 0x1a :
                case 0x1b :
                case 0x1c :
                case 0x1d :
                case 0x1e :
                case 0x1f :
                case 0x20 :
                case 0xa0 :
                    TMP = 0x2e;
                    break;
            }
            return Convert.ToChar(TMP);
        }

        public static int AddressExist(ListView lview, string str)
        {
            TMP = 200;
            for (int ctr = 0; ctr <= lview.Items.Count - 1; ctr++ )
            {
                if(lview.Items[ctr].Text == str)
                {
                    TMP = ctr;     
                }
            }
            return TMP;
        }

        public static void ReadMsg(int Addr)
        {
            if (Addr == 0xd4c8)
            {
                EmuCore.Stop();
            }
        }

        public static void WriteMsg(int Addr, int Value)
        {
            //put write msg here...
            if(Addr == 0x78)
            {
                Console.WriteLine("Addr=" + Nes.Cpu.Register.PC.ToString("X2") + ";Value=" + Value.ToString("X2"));
            }
        }
    }
}
